﻿/*
* 树展开收缩方法 2010-03-23 PM By WQY
* treeViewId: 树对象
* expandAll: 展开或收缩
*/
function TreeviewExpandCollapseAll(treeViewId, expandAll) {
    var displayState = (expandAll == true ? "none" : "block");
    var treeView = document.getElementById(treeViewId);
    if (treeView) {
        var treeLinks = treeView.getElementsByTagName("a");
        var nodeCount = treeLinks.length;

        for (i = 0; i < nodeCount; i++) {
            if (treeLinks[i].firstChild.tagName) {
                if (treeLinks[i].firstChild.tagName.toLowerCase() == "img") {
                    var currentToggleLink = treeLinks[i];
                    var childContainer = GetParentByTagName("table", currentToggleLink).nextSibling;
                    if (childContainer!=null && childContainer.style.display == displayState) {
                        eval(currentToggleLink.href);
                    }
                }
            }
        }
    }
}

function GetParentByTagName(parentTagName, childElementObj) {
    var parent = childElementObj.parentNode;
    while (parent.tagName.toLowerCase() != parentTagName.toLowerCase()) {
        parent = parent.parentNode;
    }
    return parent;
}
